package sg.edu.nus.iss.billing.service.customer;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import sg.edu.nus.iss.billing.common.exception.BadDaoCallException;
import sg.edu.nus.iss.billing.dao.customer.ComplaintsDAO;
import sg.edu.nus.iss.billing.dao.customer.ICustomerComplaintsDAO;
import sg.edu.nus.iss.billing.vo.customer.CustomerComplaintVO;

public class CustomerComplaintServiceImpl implements ICustomerComplaintService{

	private ICustomerComplaintsDAO customerComplaintDAO;
	
	public CustomerComplaintServiceImpl(){
		customerComplaintDAO = new ComplaintsDAO();
	}
	
	public CustomerComplaintVO viewCustomerComplaintById(String accountId, String complaintId){
		
		CustomerComplaintVO complaint = new CustomerComplaintVO();
		complaint = customerComplaintDAO.findComplaintById(accountId, complaintId);
		return complaint;
	}
	
	public List<CustomerComplaintVO> viewAllCustomerComplaintsByAccId(String accId){
		
		List<CustomerComplaintVO> ccList = new ArrayList<CustomerComplaintVO>();
		ccList = customerComplaintDAO.findAllComplaintsByAccountId(accId);
		return ccList;
	}

	@Override
	public boolean createCustomerComplaint(CustomerComplaintVO complaint) throws BadDaoCallException {
		complaint.setComplaintId("COMP-"+sg.edu.nus.iss.billing.common.Util.generateRandomNumer());
		complaint.setStatus("pending");
		Date date = sg.edu.nus.iss.billing.common.Util.getSystemDate();
		complaint.setDateCreated(date);
		complaint.setDateModified(date);
		customerComplaintDAO = new ComplaintsDAO();
		customerComplaintDAO.create(complaint);
		return true;
	}

	@Override
	public boolean updateCustomerComplaint(String accNo, String complaintId,
			String status) {
		int proceed = customerComplaintDAO.changeComplatintStatus(accNo, complaintId);
		return proceed==1?true:false;
	}

	@Override
	public boolean deleteComplaint(String accNo, String complaintId) {
		int check = customerComplaintDAO.changeComplatintStatus(accNo, complaintId);
		return check==1?true:false;
	}
}
